#!/bin/bash

# Slackware build script for Eduke32 HRP (High Res Pack)

# Written by B. Watson (urchlay@slackware.uk)

# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

# Note: the SlackBuild maintainer (B. Watson) has now upgraded this
# build past his hardware's ability to use it properly. I can't afford
# to buy new hardware, so this runs at slide-show framerates on my
# system. Consequently I haven't played much of the game with the HRP
# enabled. If there are major issues, I can downgrade this back to the
# previous version (4.0_321) version. Email me.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=eduke32_hires_pack
VERSION=${VERSION:-5.4}
ARCH=noarch
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

ZIPFILE="dn3d_hrp${VERSION/./}-sfx.exe"

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION
mkdir $PRGNAM-$VERSION
cd $PRGNAM-$VERSION
7za x $CWD/$ZIPFILE autoload/\* \*.txt
chown -R root:root .
find . -type d | xargs chmod 755
find . -type f | xargs chmod 644

mkdir -p $PKG/usr/share/games/eduke32
mv autoload $PKG/usr/share/games/eduke32

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION

# De-windows-ize the docs
sed -i 's,\r,,' *.txt
cp *.txt $PKG/usr/doc/$PRGNAM-$VERSION

cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
cat $CWD/README > $PKG/usr/doc/$PRGNAM-$VERSION/README

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE
